React = require('react')
Card = require('antd-mobile/lib/card')
# ListView = require('antd-mobile/lib/list-view')
Flex = require('antd-mobile/lib/flex')
Icon = require('antd-mobile/lib/icon')
Toast = require('antd-mobile/lib/toast')
RefreshControl = require('antd-mobile/lib/refresh-control')
TopNotice = require('antd-mobile/lib/notice-bar')
{StyleSheet,WebView,Linking,View,Image,Text,ScrollView,TouchableHighlight,StyleSheet,Navigator,ListView,ActivityIndicator,TouchableOpacity} = require('react-native')
Dimensions = require('Dimensions')
{ width, height } = Dimensions.get('window')
{View} = require('react-native')
{fetchGetList,fetchRefreshList} = require('../actions/page_planDetail.js')
{connect} = require('react-redux')
_ = require('underscore')
moment = require('moment')
backImg = require('../img/back.png')

Page_msgDetail = React.createClass
  _processTime:(time)->
    t = moment(time)
    t.format('DD/HHmm')
  injectedJavaScript:->
    """
    function(){
      alert(imgs);
      var imgs = querySelectorAll("img");
      alert(imgs);
      for(var i=0;i<imgs.length,i++){
        var img = imgs[i];
        img.src = "http://202.136.214.163:801/upload" + img.src;
        alert(img.src);
      }
    )();
    """
  downClickHandle:->
    debugger
    model = @props.model
    url = "http://202.136.214.163:801/FrameMain/upfile/#{model.VCCONTAIN1}"
    Linking.canOpenURL(url).then (supported)->
      if supported
        Linking.openURL(url)
      else
        Toast.show("不能识别当前网址")
  render:->
    # <View style={styles.cell}>
    #   <Text style={styles.text}>{model.VCCONTAIN}</Text>
    # </View>
    model = @props.model
    VCCONTAIN = model.VCCONTAIN.replace '/>','/>\r\n'
    debugger
    # pett = /<img.*(?=>)(.|\n)*?>/
    pett =  new RegExp "<img.*(?=>)(.|\n)*?>"
    VCCONTAIN = VCCONTAIN.replace pett,(str)->
                  debugger
                  if str.indexOf('202.136.214.163:801') is -1 && str.indexOf('data:') is -1
                    src = str[str.indexOf('src')+5..str.indexOf('>')-4]
                    #匹配img标签的正则表达式
                    #<img[\\w\\W]*?src=[\"|\']?([\\w\\W]*?)(jpg|png)[\\w\\W]*?/>
                    src = "http://202.136.214.163:801" + src
                    "<img alt='' src='#{src}' />"
                  else
                    str

    <View style={width:width,height:height,flexDirection:'column',backgroundColor:'#ffffff'}>
      <View style={{flexDirection:'row',flex:0,height:60,alignItems:'center', justifyContent:'center',backgroundColor:'#0066FF'}}>
        <View style={{flex:1,padding:10}}>
          <TouchableOpacity onPress={=>@props.navigator.pop()}>
            <Image source={backImg}  style={{height:30,width:30,resizeMode:'contain'}}/>
          </TouchableOpacity>
        </View>
        <View style={{flex:3,justifyContent:'center',alignItems:'center'}}>
          <Text style={{fontSize:20,color:'#ffffff'}}>详情</Text>
        </View>
        <View style={{flex:1,alignItems:'flex-end',padding:10}}>
        </View>
      </View>
      <View style={{flexDirection:'column',flex:1,marginTop:10,backgroundColor:'#ffffff'}}>
        <View style={styles.row}>
          <View style={styles.cell}>
            <Text style={[styles.text,{fontSize:20,fontWeight:'bold',textAlign:'center'}]}>{model.VCTITLE}</Text>
          </View>
        </View>
        <View style={styles.row}>
          <View style={styles.cell}>
            <Text style={[styles.text,{textAlign:'right'}]}>{model.DTTIME}</Text>
          </View>
        </View>
        <View style={[styles.row,{flex:10,marginBottom:40}]}>
          <WebView source={{
            html:VCCONTAIN
            }}
            canGoForward={true}
            style={{margin:5}}
            javaScriptEnabled:{true}
          >
          </WebView>


        </View>
        {
          if model.VCCONTAIN1
            <View style={{flex:1,marginBottom:20}}>
              <TouchableOpacity  onPress={@downClickHandle}>
                <View style={{paddingLeft:10,paddingRight:10}}>
                  <Text style={{color:'blue'}}>【请点击下载文件】</Text>
                </View>
              </TouchableOpacity>
            </View>
        }
      </View>
    </View>
styles = StyleSheet.create
  row:
    flexDirection:'row'
    borderWidth:1
    borderStyle:'solid'
    borderColor:'#CCCCCC'
    backgroundColor:'#ffffff'
    padding:10
    marginLeft:10
    marginRight:10
  cell:
    flex:1
    flexDirection:'row'
  text:
    flex:1


module.exports = Page_msgDetail
